package com.quanyan.orderpay.service.check.account.impl;

import com.google.common.base.Strings;
import com.quanyan.common.utils.TimeUtils;
import com.quanyan.orderpay.constants.AccountWaterDataSourceConstants;
import com.quanyan.orderpay.service.check.account.WaterMessageDecoder;
import com.quanyan.pay.entity.AccountPayWater;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;


/**
 * Created by pp.zuo on 2017/3/29.
 */
@Component("wechatRefundMessageDecoder")
public class WechatRefundMessageDecoder implements WaterMessageDecoder {
    /**
     * @param messageObject String[]
     * @return
     */
    @Override
    public AccountPayWater decode(Object messageObject) {
        AccountPayWater accountPayWater = new AccountPayWater();
        String[] stringList = (String[])messageObject;

        if (!Strings.isNullOrEmpty(stringList[15])) {
            accountPayWater.setAccountTime(TimeUtils.engStringToDate(stringList[15], "yyyy-MM-ddHH:mm:ss"));
        } else {
            accountPayWater.setAccountTime(TimeUtils.engStringToDate(stringList[14], "yyyy-MM-ddHH:mm:ss"));
        }
        accountPayWater.setTradeType(Byte.valueOf("2"));
        accountPayWater.setAmount(new BigDecimal(stringList[18]));
        accountPayWater.setOutTradeNo(stringList[16]);
        accountPayWater.setOrderNo(stringList[17]);
        accountPayWater.setDataSource(AccountWaterDataSourceConstants.WECHAT);
        accountPayWater.setBuyerAccount(stringList[7]);
        accountPayWater.setSellerId(stringList[2]);

        return accountPayWater;
    }
}
